package tech.dx.springdb.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tech.dx.springdb.entity.Parents;
import tech.dx.springdb.respository.ParentsRepository;
import tech.dx.springdb.service.ParentsService;

import java.util.Optional;

/**
 * @ClassName ParentsServiceImpl
 * @Description TODO
 * @Author daoxuan
 * @Date 2019/4/1 12:19
 * @Version 1.0
 */
@Service
public class ParentsServiceImpl implements ParentsService {

    @Autowired
    private ParentsRepository parentsRepository;

    @Override
    public Optional<Parents> getById(long id) {
        return parentsRepository.findById(id);
    }

    @Override
    public Parents add(Parents parents) {
        return parentsRepository.save(parents);
    }

    @Override
    public Parents update(Parents parents) {
        return add(parents);
    }

    @Override
    public void del(long id) {
        parentsRepository.deleteById(id);
    }

    @Override
    public boolean isExitById(long id) {
        Optional<Parents> byId = getById(id);
        return byId.isPresent()?true:false;
    }
}
